""" Viewlet Banner
"""

from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from zope.component import getMultiAdapter
from plone.app.layout.viewlets.common import SiteActionsViewlet
from Products.CMFCore.utils import getToolByName

class CMBBannerViewlet(SiteActionsViewlet):
    """This class has inheritance from another class
    defined on plone native code - 'SiteActionsViewlet'
    The main reason for this inheritance is because 
    I want another block with almost the same structure
    but with another query defined on method getBanner()
    and another template (banner.pt)
    """

    index = ViewPageTemplateFile('banner.pt')

    def getBanner(self):
        """ Returns the News for banner
        """
        catalog = getToolByName(self.context, 'portal_catalog')
        query = {
            'portal_type': 'News Item',
            'review_state': 'published',
            'sort_on': 'Date',
            'sort_order': 'reverse',
            'is_banner': True,
        }

        return catalog(**query)